home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Programming / SWI / source / src / pl-buffer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-09  |  693 b   |  34 lines

  1. /*  $Id: pl-buffer.c,v 1.6 1997/05/09 14:06:27 jan Exp $
  2.  
  3.     Designed and implemented by Jan Wielemaker
  4.     E-mail: jan@swi.psy.uva.nl
  5.  
  6.     Copyright (C) 1993 University of Amsterdam. All rights reserved.
  7. */
  8.  
  9. #include "pl-incl.h"
  10.  
  11. void
  12. growBuffer(Buffer b, long int minfree)
  13. { long osz = b->max - b->base, sz = osz;
  14.   long top = b->top - b->base;
  15.  
  16.   while( top + minfree > sz )
  17.     sz *= 2;
  18.  
  19.   if ( b->base != b->static_buffer )
  20.   { b->base = realloc(b->base, sz);
  21.     if ( !b->base )
  22.       outOfCore();
  23.   } else
  24.   { char *old = b->base;
  25.     b->base = malloc(sz);
  26.     if ( !b->base )
  27.       outOfCore();
  28.     memcpy(b->base, old, osz);
  29.   }
  30.  
  31.   b->top = b->base + top;
  32.   b->max = b->base + sz;
  33. }
  34.